package com.example.gkcircle.fragment;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import com.camnter.easyslidingtabs.widget.EasySlidingTabs;
import com.example.gkcircle.BaseFragment;
import com.example.gkcircle.MainActivity;
import com.example.gkcircle.R;
import com.example.gkcircle.adapter.TabsFragmentAdapter;
import com.example.gkcircle.fragment.love.LoveWallFragment;
import com.example.gkcircle.fragment.love.MovieFragment;
import com.example.gkcircle.fragment.love.WishWallFragment;

import java.util.LinkedList;
import java.util.List;

/**
 * 约吗Fragment
 * @author ZhouHua
 * created at 15/12/21 上午12:57
*/
public class LoveFragment extends BaseFragment implements ViewPager.OnPageChangeListener
{


	private EasySlidingTabs easySlidingTabs;
	private ViewPager easyVP;
	private TabsFragmentAdapter adapter;
	private List<Fragment> fragments;
	public static int currentItem;
	public static final String[] titles = {"约电影", "表白墙", "心愿墙"};


	@Override
	protected int setLayout() {
		return R.layout.fragment_love;
	}

	@Override
	protected void initView(View view) {
		this.easySlidingTabs = (EasySlidingTabs) view.findViewById(R.id.love_easy_sliding_tabs);
		this.easyVP = (ViewPager) view.findViewById(R.id.love_easy_vp);
	}

	@Override
	protected void initListener() {

	}

	@Override
	protected void setData() {
		this.fragments = new LinkedList<>();
		MovieFragment movie = MovieFragment.getInstance();
		LoveWallFragment loveWall = LoveWallFragment.getInstance();
		WishWallFragment wishWall = WishWallFragment.getInstance();
		this.fragments.add(movie);
		this.fragments.add(loveWall);
		this.fragments.add(wishWall);
		this.adapter = new TabsFragmentAdapter(this.getFragmentManager(), titles, this.fragments);
		this.easyVP.setAdapter(this.adapter);
		this.easySlidingTabs.setViewPager(this.easyVP);
		this.easySlidingTabs.setOnPageChangeListener(this);
	}



	@Override
	public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
	}


	@Override
	public void onPageSelected(int position) {
		MainActivity.setLoveTextColor(getActivity(),position);
		switch (position){
			case 0:
				currentItem=0;
				this.easySlidingTabs.setIndicatorColor(getResources().getColor(R.color.main));
				this.easySlidingTabs.setSelectedTextColor(getResources().getColor(R.color.main));
			    break;

			case 1:
				currentItem=1;
				this.easySlidingTabs.setIndicatorColor(getResources().getColor(R.color.love));
				this.easySlidingTabs.setSelectedTextColor(getResources().getColor(R.color.love));
				break;

			case 2:
				currentItem=2;
				this.easySlidingTabs.setIndicatorColor(getResources().getColor(R.color.wish));
				this.easySlidingTabs.setSelectedTextColor(getResources().getColor(R.color.wish));
				break;
		}


	}

	@Override
	public void onPageScrollStateChanged(int state) {

	}
}
